package com.batchengine.worker;

import com.batchengine.pool.WorkerFactory;

import java.util.concurrent.BlockingQueue;

/**
 * Created by sunil.incubator@yahoo.com.
 * User: sunil.kalva
 * Date: Jul 13, 2009
 */
public class ConsumerFactory<T> extends WorkerFactory {

    protected BlockingQueue<T> workQ;
    private boolean scheduled;

    public ConsumerFactory(BlockingQueue<T> workQ, boolean scheduled) {
        this.workQ = workQ;
        this.scheduled = scheduled;
    }

    public ConsumerFactory(BlockingQueue<T> workQ) {
        this.workQ = workQ;
    }

    @Override
    protected synchronized Worker createWorker(String workerName, long taskId) {

        if (scheduled) {
            return new ScheduledDataConsumer(workerName, taskId, workQ);
        } else {
            return new DataConsumer<T>(workerName, taskId, workQ);
        }
    }
}
